//package xcmg.device.util;
//
//import org.scribe.builder.ServiceBuilder;
//import org.scribe.builder.api.DefaultApi10a;
//import org.scribe.model.OAuthRequest;
//import org.scribe.model.Response;
//import org.scribe.model.SignatureType;
//import org.scribe.model.Token;
//import org.scribe.model.Verb;
//import org.scribe.oauth.OAuthService;
//import org.scribe.services.SignatureService;
//import org.springframework.beans.factory.annotation.Value;
//
//
///**
// * @author Mr.dong
// * @desc oauth 1.0 签名
// * @create 2021/03/10 15:33
// **/
//public class NsTokenAuth {
//
//    private static final String CONTENT_TYPE = "content-type";
//    private static final String APP_JSON = "application/json";
//
//    public static Response callWithHttpGet(String restUrl,String consumerKey, String consumerSecret,
//                                           String tokenId, String tokenSecret, String realm) {
//        OAuthService service = getService(consumerKey, consumerSecret);
//        OAuthRequest request = new OAuthRequest(Verb.GET, restUrl);
//        request.setRealm(realm);
//        service.signRequest(getToken(tokenId, tokenSecret), request);
//        return request.send();
//    }
//
//    public static Response callWithHttpPost(String restUrl,String consumerKey, String consumerSecret,
//                                            String tokenId, String tokenSecret, String realm, String jsonPayload) {
//        OAuthService service = getService(consumerKey, consumerSecret);
//        OAuthRequest request = new OAuthRequest(Verb.POST, restUrl);
//        request.setRealm(realm);
//        request.addHeader(CONTENT_TYPE, APP_JSON);
//        request.addPayload(jsonPayload);
//        service.signRequest(getToken(tokenId, tokenSecret), request);
//        return request.send();
//    }
//
//    public static Token getToken(String tokenId, String tokenSecret) {
//        return new Token(tokenId, tokenSecret);
//    }
//
//    public static OAuthService getService(String consumerKey, String consumerSecret) {
//        return new ServiceBuilder().provider(DummyService.class)
//                .apiKey(consumerKey)
//                .apiSecret(consumerSecret)
//                .signatureType(SignatureType.Header).build();
//    }
//}
